<{include file="Toy/toy_top.html"}>
    </head>
    <body>
    	<div id="wrap" style="padding-top: 0">
    		<div class="modal"></div>
			<{*include file="Toy/toy_nav.html"*}>
    		<div class="container index">
    			<div class="top">
    				<div class="ui-select">
	    				<div class="panel-title">
	    					<span>种类</span>
	    					<i></i>
	    				</div>
				        <ul class="panel" id="type" val="0">
							<{foreach from=$itemTypeKv key=key item=item}>
				        	    <li value="<{$key}>"><{$item}></li>
							<{/foreach}>
				        </ul>
				    </div>
				    
				    <div class="ui-select">
				    	<div class="panel-title">
	    					<span>状态</span>
	    					<i></i>
	    				</div>
				        <ul class="panel" id="status" val="0">
							<{foreach from=$itemStatusKv key=key item=item}>
							<li value="<{$key}>"><{$item}></li>
							<{/foreach}>

				        </ul>
				    </div>
    				<a href="<{u('myPrefer')}>" class="on">我的上架</a>

    				<a href="<{u('deal')}>" class="deal">
						交易信息
					</a>
    			</div>
    			
    			<!--无搜索结果显示-->
    			<div class="nodata" style="display: none;">未搜索到任何信息</div>
    			
    			<div class="toy-list">
    				<ul id="dataContainer">

    				</ul>
    				
    				<div class="nomore">
		    			<span>已到底</span>
		    		</div>
    			</div>

				<a href="<{u('publish')}>" class="plus"></a>
    		</div>
			<{include file="Toy/toy_foot.html"}>

    	</div>
    	<script src="<{$preStaticUrl}>Wap/js/jquery-2.1.4.min.js"></script>
    	<script src="<{$preStaticUrl}>Wap/toy/js/index.js"></script>
    	<script>

			<{if $prompt}>
			layer.open({
				content: '您有新的交换申请，是否前去查看？'
				,btn: ['是', '否']
				,yes: function(index){
					location.href="<{u('deal')}>";
				}
			});

			<{/if}>




    		$(function(){
    			$(".ui-select .panel-title").click(function(){
    				var parentNode = $(this).parent();
    				parentNode.toggleClass("show");
    				parentNode.siblings().removeClass("show");
    				if(parentNode.hasClass("show")){
    					$(".modal").show();
    				}else{
    					$(".modal").hide();
    				}
    			})
    			
    			$(".panel li").click(function(event){selectLi(event)})

				$('.modal').click(function(){
					$('.ui-select').removeClass("show");
					$(".modal").hide();
				});
				loadData();
    		})



			var loadMore = "<{U('Toy/loadMore')}>";
			var page=1;
			function loadData(){
				page=1;
				flagAjax = true;
				$('#dataContainer').empty();
				load_more({page:page});
			}

			//拖动加载
			var flagData = true;
			var flagAjax = true;
			//加载
			function load_more(postData){
				if(! flagAjax){
					return false;
				}
				flagAjax = false;
				postData.type=$('#type').attr('val');
				postData.status=$('#status').attr('val');

				$.getJSON(loadMore,postData , function(data){
					if (data.status != 0) {
						tip("数据获取失败，请稍后重试或联系管理员解决！");
					} else {
						if(parseInt(data.hasData)<=0){
							$('.nodata').show();
							$(".toy-list").hide();
							return;
						}else{
							$('.nodata').hide();
							$(".toy-list").show();
						}
						++page;
						$("#dataContainer").append(data.dataHTML);
						init_mu_timer()
						if (data.isPage) flagAjax = true;
					}
				},'json');
			}

			var tmp_scroll = 0;
			//拖动加载
			function scroll_load(postData){
				if (tmp_scroll == $(window).height() + $(window).scrollTop()) {
					return;
				}
				tmp_scroll = $(window).height() + $(window).scrollTop();
				var jia_scroll = $(document).height() - ($(window).height() + $(window).scrollTop());
				if (jia_scroll < 100 && flagData) {
					load_more(postData);
				}
			}
			$(window).scroll(function(){
				if(page==1){page=2;}
				scroll_load({page:page});
			});





			var muhandle =null;
			function init_mu_timer(){ //递减 class = mutimer 的元素
				if(muhandle != null)	clearInterval(muhandle);
				muhandle = setInterval("refresh_mu_timer()",999);
			}
			//时间递减队列
			function refresh_mu_timer(){
				var obj	= $(".mutimer");
				var l	= obj.size();
				if(l>0){
					for(var i=0;i<l;i++){
						var _that = obj[i];
						time = $(_that).attr('data-time');
						time	= time-1;
						obj[i].innerHTML =print_time(time);
						$(obj[i]).attr('data-time', time);
					}
				}else{
					clearInterval(muhandle);
				}
			}

			function print_time(time){
				if(time<= 0)	return "00:00:00";
				var h	= parseInt(time/3600);
				var d   = parseInt(h/24);
				if(d>=1){
					return d+'天'+(h%24)+'小时';
				}
				var m	= parseInt((time-h*3600)/60);
				var	s	= parseInt(time-h*3600-m*60);

				if(h<10)	h='0'+h;
				if(m<10)	m='0'+m;
				if(s<10)	s='0'+s;
				return h+":"+m+":"+s;
			}


			function selectLi(event){
				var $this=$(event.target);
				var val = $this.attr("value");
				var txt = $this.text();
				var selectNode = $this.parents(".ui-select");
				selectNode.find("span").text(txt);
				selectNode.removeClass("show");
				$(".modal").hide();

				var loc=$this.parent().attr('id');
				$('#'+loc).attr('val',val);
				switch (loc){
					case 'type':
					case 'status':
						loadData();
						break;
				}
			}
    	</script>
	</body>
</html>
